package com.zalej.cxxy;


public class Card {
    private String suit;
    private int face;

    public Card(int face, String suit){
        this.face = face;
        this.suit = suit;
    }

    public Card(){
        face = 0;
        suit = "NULL1";
    }

    public boolean setFace(int face){
        this.face = face;
        return true;
    }

    public boolean setSuit(String suit){
        this.suit = suit;
        return true;
    }

    public boolean setAll(int face, String suit){
        this.face = face;
        this.suit = suit;
        return true;
    }

    protected int getFace(){
        return this.face;
    }

    protected String getSuit(){
        return this.suit;
    }

    public String toString(){
        if (this.face==16 ||this.face==17)  return this.suit;
        if (this.face<11)                    return this.suit+this.face;
        String Z="";
        if (this.face==11)  Z="J";
        else if (this.face==12)  Z="Q";
        else if (this.face==13)  Z="K";
        else if (this.face==14)  Z="A";
        else if (this.face==15)  Z="2";
                                                return this.suit+Z;

    }
}

class Mainn {
//    final static int J = 11;
//    final static int Q = 12;
//    final static int K = 13;
//    final static int A = 14;
//    final static int TWO = 15;
//    final static int LORD = 16;
//    final static int OVERLORD = 17;




    private final static String SPADES  = "黑桃";
    private final static String HEARTS  = "红桃";
    private final static String CLUBS   = "梅花";
    private final static String DIAMONDS  = "方片";
    private final static String LORD  = "小王";
    private final static String OVERLORD  = "大王";




        public static void main(String[] args) {
            Card[] CARDS = new Card[54];        //一副牌

            for (int i = 0; i < 52; ++i) {      //成为一副牌
                CARDS[i] = new Card();
                giveValue(i+1, CARDS[i]);
                //System.out.println(CARDS[i].toString());      //测试牌值函数
            }
            CARDS[52] = new Card(16, LORD);
            CARDS[53] = new Card(17, OVERLORD);


            //牌玩法：单张牌对单张牌时，先比较点数，从小到大分别为3，4，5，6，7，8，9，10，J，Q，K,A,2,lord,overlord,点数一样时，从大到小 SPADES，HEARTS ，CLUBS，DIAMONDS
                int i = (int)(Math.random()*54);
                int j = (int)(Math.random()*54);
                //System.out.println(i);
                //System.out.println(j);
                int result = playGame(CARDS[i], CARDS[j]);

                if (result==0)  System.out.println("玩家一为"+CARDS[i].toString()+"\n玩家二为"+CARDS[j].toString()+"\n平局");
                if (result>0)  System.out.println("玩家一为"+CARDS[i].toString()+"\n玩家二为"+CARDS[j].toString()+"\n玩家一获胜");
                if (result<0)  System.out.println("玩家一为"+CARDS[i].toString()+"\n玩家二为"+CARDS[j].toString()+"\n玩家二获胜");

                //循环测试10000次运行正常





        }

        public static int playGame(Card Jack, Card Jhon){   //大于0时为Jack胜利， 小于0时为Jhon胜利，等于0时为平局
            if (Jack.getFace()>Jhon.getFace())  return 1;
            if (Jack.getFace()<Jhon.getFace())  return -1;
            else {
                //TODO
                int val = compareSuit(Jack.getSuit(), Jhon.getSuit());
                if (val>0)  return 1;//System.out.println("Jack胜");
                if (val<0)  return -1;//System.out.println("Jhon胜");
                else    return 0;

            }

        }


        public static int compareSuit(String suit1, String suit2){  //当正值时1大于2，0时相等，负值时1小于2
            if (suit1.equals(suit2))    return 0;
            int val1=999, val2=999;

            if (suit1.equals(SPADES))           val1=4;
            else if (suit1.equals(HEARTS))      val1=3;
            else if (suit1.equals(CLUBS))       val1=2;
            else if (suit1.equals(DIAMONDS))    val1=1;

            if (suit2.equals(SPADES))           val2=4;
            else if (suit2.equals(HEARTS))      val2=3;
            else if (suit2.equals(CLUBS))       val2=2;
            else if (suit2.equals(DIAMONDS))    val2=1;

            if (val1==999 || val2==999){
                System.err.println("老铁没这花色是不是搞错了？");
                return 999;
            }

            if (val1>val2)  return 1;
            if (val1<val2)  return -1;




            System.err.println("比较花色失败");
            return -999;
        }




        public static boolean giveValue(int i, Card c){
            String suit;
            if (i%4==0)    suit = SPADES;
            else if (i%3==0)    suit = HEARTS;
            else if (i%2==0)    suit = DIAMONDS;
            else                suit = CLUBS;

            c.setAll(i%13+1 , suit);
            if (i%13+1==1)  c.setFace(14);
            if (i%13+1==2)  c.setFace(15);

            return true;
            //return false;
        }


}